#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <signal.h>

#include "zlog.h"
#include "rsc.h"
//#include "sd.h"
#include "file.h"

static int demo_exit = 0;
static void sig_handle(int signo)
{
	if(signo == SIGINT)
		demo_exit = 1;
}

int main(int argc,char *argv[])
{
	int ret = 0;

	fprintf(stdout,">>>start rsc demo...\n");
	if(zlog_init(RSC_LOG_CONF)<0)
	{
		fprintf(stderr,"zlog_init failed!\n");
		exit(EXIT_FAILURE);
	}
	zlog_category_t *zc_demo = zlog_get_category("demo");

	signal(SIGINT,sig_handle);
	//ret = rsc_init_storage(rsc_sd_dev_meta,rsc_sd_cont_meta);
	ret = rsc_init_storage(rsc_file_dev_meta,rsc_file_cont_meta);
	zlog_info(zc_demo,"ret = %d\n",ret);

	int tvol = 0,fvol = 0;
	zlog_info(zc_demo,"test <rsc_get_all_vol> api: \n");
	ret = rsc_get_all_vol(&tvol,&fvol);
	zlog_info(zc_demo,"ret = %d,tvol = %dM,fvol = %dM\n",ret,tvol,fvol);

	printf(">>>Press Enter Key to Continue...\n");
	getchar();
	zlog_info(zc_demo,"test <rsc_get_root_list> api:\n");
	rsc_get_root_list(0,CONT_DATA_ALL);

	printf(">>>Press Enter Key to Continue...\n");
	getchar();
	char mpoint[64]={0};
	zlog_info(zc_demo,"test <rsc_get_avail_dev> api:\n");
	ret = rsc_get_avail_dev(100,mpoint);
	zlog_info(zc_demo,"ret = %d,mpoint = %s\n",ret,mpoint);

	printf(">>>Press Enter Key to Continue...\n");
	getchar();
	zlog_info(zc_demo,"test <rsc_dev_umount> api:\n");
	ret = rsc_dev_umount(0,NULL);
	zlog_info(zc_demo,"ret = %d\n",ret);

	printf(">>>Press Enter Key to Continue...\n");
	getchar();
	zlog_info(zc_demo,"test <rsc_dev_mount> api:\n");
	ret = rsc_dev_mount(0,NULL);
	zlog_info(zc_demo,"ret = %d\n",ret);

	printf(">>>Press Enter Key to Continue...\n");
	getchar();
	zlog_info(zc_demo,"test <rsc_dev_format> api:\n");
	ret = rsc_dev_format(0,NULL);
	zlog_info(zc_demo,"ret = %d\n",ret);

	while(!demo_exit)
	{
		sleep(1);
	}
	rsc_exit_storage();

	zlog_fini();
	fprintf(stdout,"<<<exit rsc demo...\n");

	return 0;
}

